﻿using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using System.Xml.Serialization;
using System.Xml;

namespace DllSync.Tests
{
	public class XmlSerializationFixture
	{
		[Fact]
		public void RoundtripsXml()
		{
			var v = new Version(int.MaxValue + "." + int.MaxValue + "." + int.MaxValue + "." + int.MaxValue);
			Console.WriteLine(v.ToString());

			var serializer = new XmlSerializer(typeof(DeployVersions));

			var versions = new DeployVersions()
			{
				Versions = new[]
				{
					new DeployVersion 
					{ 
						Number = "2.0.4.2", 
						Kind = "Stable",
						Text = "New!!!",
					},
					new DeployVersion 
					{ 
						Number = "2.2.1.2", 
						Kind = "Nightly",
						Text = "Risky!!!",
					},
				},
			};

			using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings { Indent = true }))
			{
				serializer.Serialize(writer, versions, new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", XmlRoot.NampespaceUri) }));
			}

			using (var reader = XmlReader.Create("SampleDeploy.xml"))
			{
				var result = (DeployVersions)serializer.Deserialize(reader);
				Assert.Equal(2, result.Versions.Length);
				Assert.Equal("2.0.5.3", result.Versions[0].Number);
				Assert.Equal("3.0.1.2538", result.Versions[1].Number);
			}

		}
	}
}
